﻿<%@ page contentType="text/html;charset=UTF-8" autoFlush="true"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
	<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <%
        String serverName = request.getServerName();
        int serverPort = request.getServerPort();
        String serverPortStr = (serverPort == 80)?"":(":"+serverPort);
        String protocol = request.getProtocol();
        String protocolStr = "http";
        String contextPath = request.getContextPath();
        String htmlBase = protocolStr+"://"+serverName+serverPortStr+contextPath+"/";
    %>
    <base href="<%=htmlBase%>"/>
    <link rel="stylesheet" rev="stylesheet" href="qa/css/main.css" type="text/css" media="screen" />
  </head>
  
  <c:choose>
  	<c:when test="${(imageIn=='question')}" >
  		<body leftmargin="0" topmargin="0" style="margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;background-color: #F4F8FC">
  	</c:when>
  	<c:when test="${(imageIn=='answer')}" >
  		<body leftmargin="0" topmargin="0" style="margin-left: 0px; margin-top: 1px; margin-right: 0px; margin-bottom: 0px">
  	</c:when>
  	<c:when test="${(imageIn=='sf')}" >
  		<body leftmargin="0" topmargin="0" style="margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px;background-color: #F4F8FC">
  	</c:when>
  	<c:when test="${(imageIn=='sfcomment')}" >
  		<body leftmargin="0" topmargin="0" style="margin-left: 0px; margin-top: 1px; margin-right: 0px; margin-bottom: 0px">
  	</c:when>
  	<c:when test="${(imageIn=='questionMod')}" >
  		<body leftmargin="0" topmargin="0" style="margin-left: 0px; margin-top: 1px; margin-right: 0px; margin-bottom: 0px">
  	</c:when>
	</c:choose>
		<c:choose>
        <c:when test="${(empty imagePath)}">
            <html:form action="/question" method="post" enctype="multipart/form-data" onsubmit="return validate(this);">
							<html:hidden property="action" value="uploadImage" />
							<html:hidden property="imageIn" value="${imageIn}" />
							<html:hidden property="imageArea" value="${imageArea}" />
							<html:file property="image" size="30"/>
							<input type="submit" value="上传" name="uploadButton" id="uploadButton"/>(小于300K,宽度小于566像素,格式:JPG,GIF,PNG)
						</html:form>
        </c:when>
        <c:when test="${(imagePath=='error')}">
        	<div style="padding-top:3px">
        	<html:messages message="true" id="msg"><c:out value="${msg}"/></html:messages>
        	<html:link page="/question.mrqa?action=uploadImage&imageIn=${imageIn}&imageArea=${imageArea}">重新上传</html:link>
        	</div>
        </c:when>
        <c:when test="${(imagePath=='limit')}">
        	<div style="padding-top:3px">
        	<html:messages message="true" id="msg"><c:out value="${msg}"/></html:messages>
        		&nbsp;
        	</div>
        </c:when>
        <c:otherwise>
        	<div style="padding-top:5px">
        		文件上传成功
        		<html:link page="/question.mrqa?action=uploadImage&imageIn=${imageIn}&imageArea=${imageArea}">继续上传</html:link>
        	</div>
        	<script language="javascript">
        		var elementName = "<c:out value="${imageArea}" />";
        		var contentName = elementName.substr(elementName.indexOf(".") + 1);
        		var formName = elementName.substr(0, elementName.indexOf("."));
        		var formIndex = 0;
        		var pos = formName.indexOf("[");
        		if(pos > 0){
        			formIndex = formName.substr(pos + 1, formName.indexOf("]") - pos - 1);
        			formName = formName.substr(0, pos);
        		}
        		var forms = this.parent.document.getElementsByName(formName);
        		if(contentName == "content"){
        			forms[formIndex].content.value = forms[formIndex].content.value + "\r\n<image=uploaded/image<c:out value="${imagePath}"/>>\r\n";
        		}else if(contentName == "description"){
        			forms[formIndex].description.value = forms[formIndex].description.value + "\r\n<image=uploaded/image<c:out value="${imagePath}"/>>\r\n";
        		}
        		</script>
        </c:otherwise>
      </c:choose>
	</body>
</html>